﻿using DA.AnimGraph;
using OdinSerializer;
using System.Collections.Generic;

namespace DA.AnimGraph.Editor {
    internal class AGANode_Revolve : AGANode_BlendBase {
        public override AGANodeModelBase modelProperty { set => model = (AGANodeModel_Revolve)value; get => model; }
        [OdinSerialize] AGANodeModel_Revolve model;
        public AGANode_Revolve(AGANodeModelBase model) : base(model) {
            inputChildren.Add(AUIDGenerator.Gen());
            inputNames.Add("port 0");
        }
        public override int Publish(List<PublishNode> outNodes, AGAPublisher.PublishContext context) {
            var pNode = new RevolvePNode();
            pNode.uuid = uuid;
            pNode.data = model.Publish(context);
            var index = outNodes.Count;
            outNodes.Add(pNode);

            pNode.inputChildren = new int[inputChildren.Count];
            for (int i = 0; i < inputChildren.Count; i++) {
                var childUuid = inputChildren[i];
                var childNode = context.subGraph.FindNextNodeInstance(uuid, childUuid) as AGANode_FunctionBase;
                if (childNode != null) pNode.inputChildren[i] = AGAPublisher.ExportNode(childNode, outNodes, context);
                else pNode.inputChildren[i] = -1;
            }

            PublishPerks(pNode, context);
            return index;
        }
    }

    [ModelOf(typeof(AGANode_Revolve))]
    internal class AGANodeModel_Revolve : AGANodeModelBase {
        public AGAFieldModel_IntLink listen = new();
        public float defaultTransitionDuration;
        
        public RevolveNode.SetupData Publish(AGAPublisher.PublishContext context) {
            var result = new RevolveNode.SetupData() {
                listenDesc = listen.Publish(context),
                defaultTransitionDuration = defaultTransitionDuration,
            };
            return result;
        }
    }
}
